package com.hatic.money;

import org.jxstar.dao.DaoParam;
import org.jxstar.service.BusinessObject;

/**
 * 投资计划基础类。
 *
 * @author TonyTan
 * @version 1.0, 2011-10-7
 */
public class PlanBO extends BusinessObject {
	private static final long serialVersionUID = 1L;

	/**
	 * 撤销厂内的投资计划
	 * @param planIds
	 * @return
	 */
	public String cancel(String[] planIds) {
		if (planIds == null || planIds.length == 0) {
			setMessage("没有选择投资计划！");
			return _returnFaild;
		}
		
		for (int i = 0; i < planIds.length; i++) {
			updateStatus(planIds[i], "91");
		}
		
		return _returnSuccess;
	}
	
	/**
	 * 提交紧急投资计划时自动创建项目立项申请。
	 * @param planIds
	 * @param userId
	 * @return
	 */
	public String auditJx(String[] planIds, String userId) {
		if (planIds == null || planIds.length == 0) {
			setMessage("没有选择子投资计划！");
			return _returnFaild;
		}
		
		PlanAuthBO planbo = new PlanAuthBO();
		for (int i = 0; i < planIds.length; i++) {
			planbo.projectCreate(planIds[i], userId);
			
			updateStatus(planIds[i], "41");
		}
		
		return _returnSuccess;
	}
	
	//在公司上报功能中不能删除厂内提交的投资计划，但可以撤销计划
	private boolean updateStatus(String planId, String status) {
		String usql = "update money_plan set plan_status = ? where plan_id = ?";
		DaoParam uparam = _dao.createParam(usql);
		uparam.addStringValue(status);
		uparam.addStringValue(planId);
		
		return _dao.update(uparam);
	}
}
